<template>
  <div class="app-container">
    <!-- 筛选条件 -->
    <el-form v-show="showSearch" ref="queryForm" :model="queryParams" :inline="true" label-width="90px" label-position="left">
      <el-form-item label="客户名称" prop="customerName">
        <el-input v-model="queryParams.customerName" placeholder="请输入客户名称" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="产品名称" prop="productName">
        <el-input v-model="queryParams.productName" placeholder="请输入产品名称" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>

    </el-form>

    <!-- 操作按钮 -->
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
      </el-col>
      <right-toolbar :show-search.sync="showSearch" @queryTable="getList" />
    </el-row>

    <!-- 表格数据 -->
    <el-table
      v-if="refreshTable"
      v-loading="loading"
      stripe
      border
      :data="businessList"
      :default-expand-all="isExpandAll"
      :tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
      :header-cell-style="{background: $store.state.app.theme.tableBack,color: $store.state.app.theme.tableColor}"
      @cell-dblclick="celldblclick"
    >
      <el-table-column label="id" align="center" prop="id" width="100px" />
      <el-table-column label="产品名称" align="center" prop="productName" />
      <el-table-column label="客户名称" align="center" prop="customerName" />
      <el-table-column label="投诉内容" align="center" prop="msg" width="800px">
        <template slot-scope="scope">
          <p class="r_text" v-text="scope.row.msg" />
        </template>
      </el-table-column>
      <!-- <el-table-column label="投诉图片" align="center" prop="carProperty" width="140px">
        <template slot-scope="scope">
          <div class="">
            <div v-if="scope.row.imgUrlData.length>0" class="r_flex_center">
              <el-image
                ref="previewImg"
                style="display: none;"
                :src="scope.row.imgUrlData[0]"
                :preview-src-list="scope.row.imgUrlData"
              />
              <p class="r_able_url r_cpter" @click="chakan">
                <i class="el-icon-view" />
                {{ scope.row.imgUrlData[0] ? '点击查看' : '没有上传图片' }}
              </p>
            </div>
            <p v-else>无预览图</p>
          </div>
        </template>
      </el-table-column> -->
      <el-table-column label="是否回复" align="center" prop="status">
        <template slot-scope="scope">
          <div v-if="scope.row.status == 0">未回复</div>
          <div v-else-if="scope.row.status == 1">已回复</div>
          <div v-else>--</div>
        </template>
      </el-table-column>
      <el-table-column label="产品类型" align="center" prop="type">
        <template slot-scope="scope">
          <div v-if="scope.row.type == 1">大额贷</div>
          <div v-else-if="scope.row.type == 2">极速贷</div>
          <div v-else>--</div>
        </template>
      </el-table-column>

      <el-table-column v-if="checkPermi(['system:richText:edit', 'system:richText:remove'])" label="操作" align="center">
        <template slot-scope="scope">
          <el-button v-hasPermi="['system:richText:edit']" size="mini" type="text" @click="handleUpdate(scope.row)">回复</el-button>
          <el-button v-if="scope.row.parentId != 0" v-hasPermi="['system:richText:remove']" size="mini" type="text" @click="handleDelete(scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <!-- 分页 -->
    <el-row :gutter="24" class="mb8" style="margin: 20px 0px">
      <el-col :span="24" style="display: flex; justify-content: flex-end; padding: 0px">
        <el-pagination
          background
          layout="prev, pager, next, sizes, total"
          :page-sizes="[10, 50, 100, 200]"
          :page-size="queryParams.pageSize"
          :total="totalPage"
          @current-change="handlePageChange"
          @size-change="
            newSize => {
              queryParams.pageSize = newSize;
              getList();
            }
          "
        />
      </el-col>
    </el-row>

    <!-- 对话框-修改 -->
    <el-dialog :title="'回复投诉信息' " :visible.sync="openDialog" width="1000px" append-to-body>
      <el-form style="padding: 0px 50px;" label-width="120px">
        <div class="">
          <el-row>
            <el-col :span="24">
              <el-form-item label="投诉产品" prop="">
                {{ newForm.productName }}
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <el-form-item label="投诉客户" prop="">
                {{ newForm.customerName }}
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <el-form-item label="投诉内容" prop="">
                <div v-html="newForm.msg" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <el-form-item label="上传图片" prop="">
                <div v-if="newForm.imgUrlData.length>0" class="r_flex" style="flex-wrap: wrap;">
                  <el-image v-for="(data, index) in newForm.imgUrlData" :key="index" style="width: 100px;margin: 10px;" :src="data" />
                </div>
              </el-form-item>
            </el-col>
          </el-row>

          <el-row>
            <el-col :span="24">
              <el-form-item label="回复内容" prop="">
                <el-input
                  v-model="hfText"
                  type="textarea"
                  :rows="6"
                  placeholder="请输入内容"
                />
              </el-form-item>
            </el-col>
          </el-row>
        </div>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" :loading="submitLoad" @click="submitForm">确 定</el-button>
        <el-button @click="openDialog = false">取 消</el-button>
      </div>
    </el-dialog>

  </div>
</template>

<script>
import { complaintList, delcomplaint, upcomplaint, addcomplaint } from '@/api/business/richText'
import '@riophae/vue-treeselect/dist/vue-treeselect.css'
import { checkPermi } from '@/utils/permission' // 权限判断函数

export default {
  name: 'RichTsList',
  data() {
    return {
      // 遮罩层
      loading: true,
      // 修改渠道loading
      submitLoad: false,
      // 显示搜索条件
      showSearch: true,
      // 表格树数据
      businessList: [],
      // 对话框类型
      titleDialog: '',
      // 是否显示对话框
      openDialog: false,
      // 是否展开，默认全部展开
      isExpandAll: true,
      // 重新渲染表格状态
      refreshTable: true,
      // 查询参数
      queryParams: {
        pageNum: 1, // 当前页数
        pageSize: 10, // 分页大小
        productName: '',
        customerName: ''
      },
      // 上传图片选项
      ossImageUrl: [],
      // 数据总条数
      totalPage: 0,
      // 表单参数
      formDialog: {
      },
      newFormDialog: {
      },
      newForm: {
        imgUrlData: []
      },
      hfText: '',
      // h5模板数组
      H5Array: [],
      // 极速贷数组
      jisuArray: [],
      // 修改富文本id
      upId: 0
    }
  },
  created() {
    // 分页数据
    this.getList()
  },
  methods: {
    checkPermi,
    chakan() {
      this.$refs.previewImg.showViewer = true
    },
    // 查询列表
    getList() {
      this.loading = true
      complaintList(this.queryParams).then(response => {
        this.businessList = response.rows
        this.businessList.imgUrlData = []
        this.totalPage = response.total
        this.businessList.map(data => {
          data.imgUrlData = data.sysOssVos.map(img => img.url)
        })

        this.loading = false
      }).finally(() => { this.loading = false })
    },
    // 搜索按钮操作
    handleQuery() {
      this.getList()
    },
    // 重置按钮操作
    resetQuery() {
      this.resetForm('queryForm')
      this.handleQuery()
    },
    // 删除按钮操作
    handleDelete(row) {
      this.$modal
        .confirm('是否确认删除')
        .then(function() {
          return delcomplaint(row.id)
        })
        .then(() => {
          this.getList()
          this.$modal.msgSuccess('删除成功')
        })
        .catch(() => {})
    },
    // 新增按钮操作
    handleAdd() {
      this.upId = 0
      this.titleDialog = 'add'
      this.openDialog = true
    },
    // 修改按钮操作
    handleUpdate(row) {
      this.newForm = JSON.parse(JSON.stringify(row))
      // this.hfText = this.newForm.replyMsg
      this.upId = row.id
      this.titleDialog = 'up'
      this.openDialog = true
    },
    // 保存成功
    upRichText() {
      this.openDialog = false
      // 分页数据
      this.getList()
    },
    // 修改按钮操作
    submitForm() {
      this.submitLoad = true
      this.newFormDialog = {}
      this.newFormDialog = JSON.parse(JSON.stringify(this.newForm))
      this.newFormDialog.replyMsg = this.hfText
      this.newFormDialog.status = 1
      upcomplaint(this.newFormDialog)
        .then(() => {
          this.submitLoad = false
          this.openDialog = false
          this.getList()
          this.$modal.msgSuccess('修改成功')
        })
        .catch(() => {
          this.submitLoad = false
        })
    },
    // 表单重置
    reset() {
      this.form = {
        parentId: '',
        deptName: '',
        pdAmount: '',
        tag: '',
        leader: '',
        type: '',
        url: '',
        zkStatus: '1'
      }
      this.resetForm('form')
    },
    // 分页请求
    handlePageChange(data) {
      this.queryParams.pageNum = data
      this.getList()
    },
    // 双击复制
    celldblclick(row, column, cell, event) {
      if (!column.property) return
      if (!row[column.property]) return
      const oInput = document.createElement('input')
      oInput.value = row[column.property]
      document.body.appendChild(oInput)
      oInput.select()
      document.execCommand('Copy')
      this.$message.success({
        message: '复制成功',
        showClose: true
      })
      oInput.remove()
    }
  }
}
</script>
